package org.movieexample.ws;

import org.movieexample.www.movie.GetAllMovieData;
import org.movieexample.www.movie.GetAllMovieDataFault;
import org.movieexample.www.movie.GetAllMovieDataResponse;
import org.movieexample.www.movie.GetMovieByGenre;
import org.movieexample.www.movie.GetMovieByGenreFault;
import org.movieexample.www.movie.GetMovieByGenreResponse;
import org.movieexample.www.movie.GetMovieByName;
import org.movieexample.www.movie.GetMovieByNameFault;
import org.movieexample.www.movie.GetMovieByNameResponse;
import org.movieexample.www.movie.GetMovieByTheatre;
import org.movieexample.www.movie.GetMovieByTheatreFault;
import org.movieexample.www.movie.GetMovieByTheatreResponse;
import org.movieexample.www.movie.GetMovieByTime;
import org.movieexample.www.movie.GetMovieByTimeFault;
import org.movieexample.www.movie.GetMovieByTimeResponse;
import org.movieexample.www.movie.GetMovieByType;
import org.movieexample.www.movie.GetMovieByTypeFault;
import org.movieexample.www.movie.GetMovieByTypeResponse;
import org.movieexample.www.movie.MovieData;
import org.movieexample.www.movie.MovieList;



public class MovieBusiness implements MovieServiceSkeletonInterface
{


	@Override
	public GetMovieByGenreResponse getMovieByGenre(
			GetMovieByGenre getMovieByGenre)
			throws GetMovieByGenreFaultException {
		MovieList movielist;
		GetMovieByGenreResponse result = new GetMovieByGenreResponse();
		try 
		{
			MovieDAO moviedao=new MovieDAO();

			movielist=moviedao.getMovieInfoByGenre(getMovieByGenre.getIn());
			result.setOut(movielist);
			return result;
		} 
		catch (Exception e) 
		{
			GetMovieByGenreFault excep = new GetMovieByGenreFault();
			excep.setGetMovieByGenreFault(ErrorMessages.ServiceUnavailableError);
			GetMovieByGenreFaultException typefault = new GetMovieByGenreFaultException();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
	}

	@Override
	public GetMovieByNameResponse getMovieByName(GetMovieByName getMovieByName)
			throws GetMovieByNameFaultException {
		MovieData movie;
		GetMovieByNameResponse result = new GetMovieByNameResponse();
		try 
		{
			MovieDAO moviedao=new MovieDAO();

			movie=moviedao.getMovieInfoByName(getMovieByName.getIn());
			result.setOut(movie);
		} 
		catch (Exception e) 
		{
			GetMovieByNameFault excep = new GetMovieByNameFault();
			excep.setGetMovieByNameFault(ErrorMessages.ServiceUnavailableError);
			GetMovieByNameFaultException typefault = new GetMovieByNameFaultException();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
		return result;
	}

	@Override
	public GetMovieByTimeResponse getMovieByTime(GetMovieByTime getMovieByTime)
			throws GetMovieByTimeFaultException {
		MovieList movielist;
		GetMovieByTimeResponse result = new GetMovieByTimeResponse();
		try 
		{
			MovieDAO moviedao=new MovieDAO();

			movielist=moviedao.getMovieInfoByTime(getMovieByTime.getIn());
			result.setOut(movielist);
		} 
		catch (Exception e) 
		{
			GetMovieByTimeFault excep = new GetMovieByTimeFault();
			excep.setGetMovieByTimeFault(ErrorMessages.ServiceUnavailableError);
			GetMovieByTimeFaultException typefault = new GetMovieByTimeFaultException();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
		return result;
	}

	@Override
	public GetAllMovieDataResponse getAllMovieData(
			GetAllMovieData getAllMovieData)
			throws GetAllMovieDataFaultException {
		MovieList movielist;
		GetAllMovieDataResponse result = new GetAllMovieDataResponse();
		try 
		{
			MovieDAO moviedao=new MovieDAO();

			movielist=moviedao.getAllMovieData();
			result.setOut(movielist);
		} 
		catch (Exception e) 
		{
			GetAllMovieDataFault  excep = new GetAllMovieDataFault();
			excep.setGetAllMovieDataFault(ErrorMessages.ServiceUnavailableError);			
			GetAllMovieDataFaultException typefault = new GetAllMovieDataFaultException();
			typefault.setFaultMessage(excep);
			throw typefault;
		}
		
		return result;
	}


	@Override
	public GetMovieByTheatreResponse getMovieByTheatre(
			GetMovieByTheatre getMovieByTheatre)
			throws GetMovieByTheatreFaultException {
		MovieList movielist;
		GetMovieByTheatreResponse result = new GetMovieByTheatreResponse();
		try 
		{
			MovieDAO moviedao=new MovieDAO();
			movielist=moviedao.getMovieInfoByTheatre(getMovieByTheatre.getIn());
			result.setOut(movielist);
			return result;
		} 
		catch (Exception e) 
		{
			
			GetMovieByTheatreFault fault = new GetMovieByTheatreFault();
			fault.setGetMovieByTheatreFault(ErrorMessages.ServiceUnavailableError);
			GetMovieByTheatreFaultException typefault = new GetMovieByTheatreFaultException();
			typefault.setFaultMessage(fault);
			throw typefault;
		}
	}

	@Override
	public GetMovieByTypeResponse getMovieByType(GetMovieByType getMovieByType)
			throws GetMovieByTypeFaultException {
		MovieList movielist;
		GetMovieByTypeResponse result = new GetMovieByTypeResponse();
		try 
		{
			MovieDAO moviedao=new MovieDAO();
		    movielist = moviedao.getMovieInfoByType(getMovieByType.getIn());
			result.setOut(movielist);
			return result;
		} 
		catch (Exception e) 
		{
			GetMovieByTypeFault fault = new GetMovieByTypeFault();
			fault.setGetMovieByTypeFault(ErrorMessages.ServiceUnavailableError);
			GetMovieByTypeFaultException typefault = new GetMovieByTypeFaultException();
			typefault.setFaultMessage(fault);
			throw typefault;
		}
	}
	
}
